<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ include file="/share/_meta.jsp" %>
<%@ include file="/share/_footer.jsp" %>
<div class="page-container">
    <form class="form form-horizontal" id="myform" action="" method="post">
        <input type="hidden" value="${housinginfo.id}" name="housingId">

        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>小区名称：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text radius size-L" value="${housinginfo.name}" placeholder="小区名称" id="housingInfoName" name="housingInfoName" readonly="true">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>房间号：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <select class="form-control" name="roominfoId" id="roominfoId" required>
                    <option value="">请选择房间号</option>
                    <c:forEach items="${roomlist}" var="item">
                        <option value="${item.id}">${item.name}</option>
                    </c:forEach>
                </select>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2">业主姓名：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text radius size-L" value="" name="owner" id="owner" readonly="true">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2">上期水表数：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text radius size-L" value="" name="oldWaterNum" id="oldWaterNum" readonly="true">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2">本期水表数：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text radius size-L" value="" name="waterNum" required>
            </div>
        </div>
        <!-- <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2">本期用量：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text radius size-L" value="" name="useNum">
            </div>
        </div> -->

        <div class="row cl">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-2">
                <button type="submit" class="btn btn-secondary radius size-L">保&nbsp;存</button>
            </div>
        </div>
    </form>
</div>
<script type="text/javascript" src="${pageContext.request.contextPath}/h-ui/lib/jquery.validation/1.14.0/jquery.validate.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/h-ui/lib/jquery.validation/1.14.0/messages_zh.js"></script>
<script type="text/javascript">
    $("#myform").validate({
        submitHandler:function(form) {
            $(form).ajaxSubmit({
                type: 'post',
                url: "${pageContext.request.contextPath }/rest/watermeter/saveOrUpdateWatermeter",
                beforeSubmit: function () {
                    layer.load();
                },
                success: function(data){
                	layer.closeAll('loading');
                    if (data.success) {
                    	layer.msg(data.message);
                    }else {
                        layer.msg(data.message);
                    }
                },
                error: function(XmlHttpRequest, textStatus, errorThrown){
                    layer.closeAll('loading');
                    layer.msg('error!',{icon:1,time:1000});
                }
            });
        }
    });

    //下拉框事件
    $("#roominfoId").change(function(){
    	$("#owner").val('');
    	$("#oldWaterNum").val('');
        changChild($(this).val());
    });

    function changChild(rid){
    	if(rid!=null&&rid!=""){
    		$.post("${pageContext.request.contextPath }/rest/watermeter/queryOwnerByRoomId",{"roomId":rid},function(json){
                $("#owner").val(json.roomOwner);
                $("#oldWaterNum").val(json.waterNum);
            },'json');
    	}       
    }

</script>